#include<stdio.h>
//#include<stdlib.h>

void print(int* p, int sz)
{
	for (int i = 0; i < sz; i++)
	{
		printf("%d ", p[i]);
	}
}
int compar(const void* p1, const void* p2)
{
	return *(int*)p1 - *(int*)p2;
}

void sweap(char* p1, char* p2, size_t width)
{
	for (int i = 0; i < width; i++)
	{
		char tem = *p1;
		*p1 = *p2;
		*p2 = tem;
		p1++;
		p2++;
	}
}

void my_qsort(void* p, size_t sz, size_t width, int (*ptr)(const void*, const void*))
{
	int i = 0;
	for (i = 0; i < sz - 1; i++)
	{
		for (int j = 0; j < sz - i - 1; j++)
		{
			if (compar((char*)p + j * width, (char*)p + (j + 1) * width) > 0)
			{
				sweap((char*)p + j * width, (char*)p + (j + 1) * width, width);
			}
		}
	}
}
void test()
{
	int arr[10] = { 3,4,5,2,1,6,7,8,9,0 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	my_qsort(arr, sz, sizeof(arr[0]), compar);
	int* p = arr;
	print(p, sz);
}
int main()
{
	test();
	return 0;
}
